#ifndef RIGHTSHIFT_H
#define RIGHTSHIFT_H

#include <iostream>
using namespace std;

template<typename T>
void reverseArray(T arr[], int start, int end) {
    while (start < end) {
        T temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}

template<typename T>
void rightShiftSequence(T arr[], int length, int n) {
    if (length == 0) {
        cout << "数组为空，无法右移！" << endl;
        return;
    }
    
    if (n % length == 0) {
        cout << "移动位数为长度的整数倍，数组保持不变" << endl;
        return;
    }
    
    n = n % length;
    
    if (n < 0) {
        cout << "移动位数不能为负数！" << endl;
        return;
    }
    
    reverseArray(arr, 0, length - 1);
    reverseArray(arr, 0, n - 1);
    reverseArray(arr, n, length - 1);
}

template<typename T>
void displayArray(T arr[], int length) {
    cout << "(";
    for (int i = 0; i < length; i++) {
        cout << arr[i];
        if (i < length - 1) {
            cout << ",";
        }
    }
    cout << ")" << endl;
}

#endif